var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){
	var paramMap = params();
	var id = paramMap['id'];

	$("#backList").click(function(){
		var url=server_url+'/buyerManage/list.do';
		tl_config.last_url=url;
		tl_config.loadToWorkArea(url);
	});
	$.ajax({
		type : 'GET',
		contentType : 'application/json',
		async : false,
		data : {
			buyerid : id,
			token:token
		},
		url : server_url+'/rest/buyerManage/getBuyer.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if (data.retCode == "0000") {
				pasteData(data.data.buyer);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});
	
});

function isEmpty(data){
	if(data==null||data==undefined||data.length==0){
		return true;
	}else{
		return false;
	}
}
function pasteData(data){
	console.log(data);
	$("#buyerId").val(data.buyerId);
	$("#buyerName").text(data.buyerName);
	$("#buyerTel").text(data.buyerTel);
	$("#addTime").text(data.addTime);
	$("#address").text(data.provinceName+","+data.cityName+","+data.countyName+","+data.address);

	var consignees = data.consignees;
	if(exist(consignees)){
		_.map(consignees,function(obj){
			console.log(obj);
			$("<tr><td>"+obj.consigneer+"</td> " +
					"<td>"+obj.mobile+"</td>  " +
					"<td>"+obj.provinceName+obj.cityName+obj.countyName+obj.consigneerAddress+"</td>  " +
					"<td>&nbsp;</td>  " +
					"</tr>").appendTo($("table"));
		});
	}
	$("#remark").text(data.remark);
};
